//
//  AppHelper.swift
//  SeeFM_Swift
//
//  Created by CBCT_MBP on 2021/7/13.
//
//  这里存放一些封装的常用方法

import UIKit

class AppHelper: NSObject {

    static let isCheck = !isAuditing()
    

    static func openLogin(_ state: ((_ success: Bool)->())? ) {
        guard let nav = AppHelper.navigationController() else { return }
        
        let login = SFLoginController()
        login.complete = { v in
            state?(v)
        }
        let lv = SFNavigationController(rootViewController: login)
        lv.modalPresentationStyle = .fullScreen
        nav.present(lv, animated: true, completion: nil)
    }
    
    static func isAuditing() -> Bool {
        let serverBuild = Int(Config.appConfig().serverInfo?.i_aud_ver ?? "100")!
        let appBuild = Int(SFNetBean.shared.appBuild())!
        return appBuild < serverBuild
    }
    
    static func showInfo(info: String?) {
        let m = info != nil ? info : "请求失败"
        
        SVProgressHUD.showInfo(withStatus: m)
        SVProgressHUD.setDefaultMaskType(.none)
        SVProgressHUD.setImageViewSize(.zero)
        SVProgressHUD.setBackgroundColor(kBlackColor_50)
        SVProgressHUD.setForegroundColor(kWhiteColor)
        DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
            SVProgressHUD.dismiss()
        }
    }
    
    static func navigationController() -> UINavigationController? {
        let tabVC: SFTabbarController = UIApplication.shared.delegate?.window??.rootViewController as! SFTabbarController
        guard let v = tabVC.currentNavigationVC else { return nil }
        return v
    }
}
